export function TMapAddress(location) {
    return new Promise((resolve, prject) => {
        window.handleResponse = function(data) {
            resolve(data.result)
        }
        let url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + location +"&output=jsonp&key=KVZBZ-Y7BKJ-YJSFR-DPR2M-LRW5O-EIFW6&callback=handleResponse";
        var script = document.createElement('script')
        script.src = url
        document.body.appendChild(script)
    })
}

export function SearchAddress(keywords) {
    return new Promise((resolve, reject) => {
        window.handleRes = function(data) {
            resolve(data.data)
        }
        let url = "https://apis.map.qq.com/ws/place/v1/search?boundary=region(中国,0)&keyword=" + keywords + "&output=jsonp&page_size=10&page_index=1&key=KVZBZ-Y7BKJ-YJSFR-DPR2M-LRW5O-EIFW6&callback=handleRes";
        var script = document.createElement('script')
        script.src = url
        document.body.appendChild(script)
    })
}

export function addressToTMap(address) {
    return new Promise((resolve, reject) => {
        window.handleResult = function(data) {
            console.log(data, '地址解析')
            if (data.status == 0)
            {
                resolve(data.result)
            }
            else
            {
                resolve()
            }
        }
        let url = "https://apis.map.qq.com/ws/geocoder/v1?address=" + address + "&output=jsonp&key=KVZBZ-Y7BKJ-YJSFR-DPR2M-LRW5O-EIFW6&callback=handleResult";
        var script = document.createElement('script')
        script.src = url
        document.body.appendChild(script)
    })
}